home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / progtool / c / egem_210 / egem / source / objc.c < prev    next >
C/C++ Source or Header  |  1995-11-25  |  8KB  |  399 lines

  1.  
  2. #include <string.h>
  3. #include "proto.h"
  4.  
  5. #ifndef SMALL_EGEM
  6. void ob_clear_edit(reg OBJECT *obj)
  7. {
  8.     reg int flags;
  9.  
  10.     for (;;)
  11.     {
  12.         flags = obj->ob_flags;
  13.         if (flags & EDITABLE)
  14.             ob_get_text(obj,0,TRUE);
  15.         if (flags & LASTOB)
  16.             break;
  17.         else
  18.             obj++;
  19.     }
  20. }
  21. #endif
  22.  
  23. static int ob_state(DIAINFO *info,OBJECT *tree,int obj,int masc,int set,int draw)
  24. {
  25.     reg OBJECT *ob_ptr;
  26.     reg int state,old_state;
  27.  
  28.     ob_ptr = &tree[obj];
  29.     old_state = state = ob_ptr->ob_state;
  30.  
  31.     switch (set)
  32.     {
  33.     case SET_STATE:
  34.         state |= masc;
  35.         break;
  36.     case CLEAR_STATE:
  37.         state &= ~masc;
  38.         break;
  39.     default:
  40.         state ^= masc;
  41.     }
  42.  
  43.     if (state!=old_state)
  44.     {
  45.         if (info)
  46.         {
  47.             if (draw)
  48.                 ob_draw_chg(info,obj,NULL,state,FALSE);
  49.         }
  50.         else if (draw)
  51.         {
  52.             wind_update(BEG_UPDATE);
  53.             objc_change(tree,obj,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,state,1);
  54.             wind_update(END_UPDATE);
  55.         }
  56.         ob_ptr->ob_state = state;
  57.         return (TRUE);
  58.     }
  59.     else
  60.         return (FALSE);
  61. }
  62.  
  63. int ob_select(DIAINFO *info,OBJECT *tree,int obj,int select,int draw)
  64. {
  65.     return(ob_state(info,tree,obj,SELECTED,select,draw));
  66. }
  67.  
  68. int ob_disable(DIAINFO *info,OBJECT *tree,int obj,int disable,int draw)
  69. {
  70.     reg int changed;
  71.  
  72.     if (draw && info)
  73.     {
  74.         if ((changed=ob_state(NULL,tree,obj,DISABLED,disable,FALSE))!=0)
  75.             ob_draw(info,obj);
  76.     }
  77.     else
  78.         changed = ob_state(info,tree,obj,DISABLED,disable,draw);
  79.     return (changed);
  80. }
  81.  
  82. int ob_draw(DIAINFO *info,int obj)
  83. {
  84.     return(ob_draw_chg(info,obj,NULL,FAIL,FALSE));
  85. }
  86.  
  87. int ob_draw_list(reg DIAINFO *info,reg int *ob_lst,reg GRECT *area)
  88. {
  89.     if (info->di_flag>CLOSED && !info->di_win->iconified && _popup==0 && (_dia_len==0 || info==_dia_list[_dia_len-1]))
  90.     {
  91.         reg OBJECT *tree = info->di_tree;
  92.         GRECT win,work;
  93.  
  94.         if (area)
  95.             win = *area;
  96.         else
  97.             win = *(GRECT *) &tree->ob_x;
  98.  
  99.         if (rc_intersect(&desk,&win))
  100.         {
  101.             reg int *objs,ob;
  102.  
  103.         #ifndef SMALL_EGEM
  104.             if (info->di_cursor)
  105.             {
  106.                 objs = ob_lst;
  107.                 ob = info->di_ed_obj;
  108.                 while (*objs)
  109.                     if (*objs++==ob)
  110.                     {
  111.                         _cursor_off(info);
  112.                         break;
  113.                     }
  114.             }
  115.         #endif
  116.  
  117.             if (info->di_flag<WINDOW)
  118.             {
  119.                 _clip_rect(&win);
  120.                 while ((ob=*ob_lst++)>0)
  121.                     objc_draw(tree,ob,MAX_DEPTH,win.g_x,win.g_y,win.g_w,win.g_h);
  122.                 _clip_rect(&desk);
  123.             }
  124.             else
  125.             {
  126.                 wind_update(BEG_UPDATE);
  127.                 window_first(info->di_win,&work);
  128.                 while (work.g_w>0 && work.g_h>0)
  129.                 {
  130.                     if (rc_intersect(&win,&work))
  131.                     {
  132.                         _clip_rect(&work);
  133.  
  134.                         objs = ob_lst;
  135.                         while ((ob=*objs++)>0)
  136.                             objc_draw(tree,ob,MAX_DEPTH,work.g_x,work.g_y,work.g_w,work.g_h);
  137.                     }
  138.                     window_next(info->di_win,&work);
  139.                 }
  140.                 _clip_rect(&desk);
  141.                 wind_update(END_UPDATE);
  142.             }
  143.  
  144.             return (TRUE);
  145.         }
  146.     }
  147.  
  148.     return (FALSE);
  149. }
  150.  
  151. int ob_draw_chg(DIAINFO *info,int obj,GRECT *area,int new_state,boolean top)
  152. {
  153.     reg OBJECT *tree = info->di_tree;
  154.     int exit = FALSE;
  155.  
  156.     if (info->di_flag==CLOSED || info->di_win->iconified || _popup || (_dia_len>0 && info!=_dia_list[_dia_len-1]))
  157.     {
  158.         if (new_state>=0)
  159.         {
  160.             if (tree!=NULL)
  161.                 tree[obj].ob_state = new_state;
  162.             else
  163.                 exit = FAIL;
  164.         }
  165.     }
  166.     else
  167.     {
  168.         reg OBJECT *ob = tree + obj;
  169.         GRECT win,work;
  170.  
  171.         if (area)
  172.             win = *area;
  173.         else
  174.             win = *(GRECT *) &tree->ob_x;
  175.  
  176.         if (rc_intersect(&desk,&win))
  177.         {
  178.         #ifndef SMALL_EGEM
  179.             if (info->di_cursor && (obj==info->di_ed_obj || obj==0))
  180.                 _cursor_off(info);
  181.         #endif
  182.  
  183.             if (top || info->di_flag<WINDOW)
  184.             {
  185.                 _clip_rect(&win);
  186.                 if (new_state>=0)
  187.                     objc_change(tree,obj,0,win.g_x,win.g_y,win.g_w,win.g_h,new_state,1);
  188.                 else
  189.                     objc_draw(tree,obj,MAX_DEPTH,win.g_x,win.g_y,win.g_w,win.g_h);
  190.                 _clip_rect(&desk);
  191.             }
  192.             else
  193.             {
  194.                 int old_state = ob->ob_state;
  195.  
  196.                 wind_update(BEG_UPDATE);
  197.                 window_first(info->di_win,&work);
  198.                 while (work.g_w>0 && work.g_h>0)
  199.                 {
  200.                     if (rc_intersect(&win,&work))
  201.                     {
  202.                         _clip_rect(&work);
  203.                         if (new_state>=0)
  204.                         {
  205.                             objc_change(tree,obj,0,work.g_x,work.g_y,work.g_w,work.g_h,new_state,1);
  206.                             ob->ob_state = old_state;
  207.                         }
  208.                         else
  209.                             objc_draw(tree,obj,MAX_DEPTH,work.g_x,work.g_y,work.g_w,work.g_h);
  210.                     }
  211.                     window_next(info->di_win,&work);
  212.                 }
  213.                 _clip_rect(&desk);
  214.                 wind_update(END_UPDATE);
  215.             }
  216.             exit = TRUE;
  217.         }
  218.  
  219.         if (new_state>=0)
  220.             ob->ob_state = new_state;
  221.     }
  222.  
  223.     return (exit);
  224. }
  225.  
  226. int ob_radio(OBJECT *tree,int parent,int object)
  227. {
  228.     reg int i,radio = 0,first = tree[parent].ob_head,last = tree[parent].ob_tail;
  229.     reg OBJECT *obj;
  230.  
  231.     i = first;
  232.     while (i>=first && i<=last)
  233.     {
  234.         obj = tree + i;
  235.         if (obj->ob_flags & RBUTTON)
  236.         {
  237.             if (!(obj->ob_state & DISABLED))
  238.              {
  239.                 if (radio==object)
  240.                     obj->ob_state |= SELECTED;
  241.                 else if (obj->ob_state & SELECTED)
  242.                 {
  243.                     if (object>=0)
  244.                         obj->ob_state &= ~SELECTED;
  245.                     else
  246.                         object = radio;
  247.                 }
  248.             }
  249.             radio++;
  250.         }
  251.         i = obj->ob_next;
  252.     }
  253.     return (object);
  254. }
  255.  
  256. int ob_get_parent(OBJECT *tree,int obj)
  257. {
  258.     reg int index = 0,parent = 0;
  259.  
  260.     do
  261.     {
  262.         if (tree->ob_head<=obj && tree->ob_tail>=obj)
  263.             parent = index;
  264.         tree++;index++;
  265.     }
  266.     while (!(tree->ob_flags & LASTOB));
  267.  
  268.     return(parent);
  269. }
  270.  
  271. int _get_hotkey(OBJECT *tree,int button)
  272. {
  273.     reg OBJECT *obj = &tree[button];
  274.     reg int i,last,type;
  275.  
  276.     type = obj->ob_type & G_TYPE;
  277.     if ((unsigned char) type!=G_USERDEF)
  278.         type = (unsigned char) type;
  279.  
  280.     switch (type)
  281.     {
  282.     case G_IND:
  283.     case G_HOTKEY:
  284.         return (button);
  285.     case G_CHK:
  286.     case G_RB:
  287.         if ((button = obj->ob_next)<0)
  288.             return (FAIL);
  289.         obj = &tree[button];
  290.     case G_TEXT:
  291.     case G_FTEXT:
  292.     case G_BOXTEXT:
  293.     case G_FBOXTEXT:
  294.     case G_STRING:
  295.     case G_BUTTON:
  296.     case G_BOXCHAR:
  297.         if ((i=obj->ob_head)>0)
  298.             for (last=obj->ob_tail,obj=&tree[i];i<=last;i++,obj++)
  299.             {
  300.                 switch (obj->ob_type & G_TYPE)
  301.                 {
  302.                 case G_IND:
  303.                 case G_HOTKEY:
  304.                     return (i);
  305.                 }
  306.             }
  307.     }
  308.  
  309.     return (FALSE);
  310. }
  311.  
  312. char ob_get_hotkey(OBJECT *tree,int button)
  313. {
  314.     reg int obj = _get_hotkey(tree,button);
  315.  
  316.     if (obj>0)
  317.         return(tree[obj].ob_state>>8);
  318.     else
  319.         return(0);
  320. }
  321.  
  322. int ob_set_hotkey(OBJECT *tree,int button,char hot)
  323. {
  324.     reg int obj = _get_hotkey(tree,button);
  325.  
  326.     if (obj>0)
  327.     {
  328.         reg int width,parent = ob_get_parent(tree,obj);
  329.         reg OBJECT *ob_ptr = &tree[obj],*par_ptr = &tree[parent];
  330.         reg char *text = ob_get_text(tree,parent,FALSE),*pos;
  331.  
  332.         if (text && ((pos = strchr(text,UpperChar(hot)))!=NULL || (pos = strchr(text,LowerChar(hot)))!=NULL))
  333.         {
  334.             width = (int) strlen(text);
  335.  
  336.             switch((unsigned char) par_ptr->ob_type)
  337.             {
  338.             case G_TEXT:
  339.             case G_FTEXT:
  340.             case G_BOXTEXT:
  341.             case G_FBOXTEXT:
  342.                 if (par_ptr->ob_spec.tedinfo->te_font==SMALL)
  343.                     width *= gr_sw;
  344.                 else
  345.                     width *= gr_cw;
  346.  
  347.                 switch (par_ptr->ob_spec.tedinfo->te_just)
  348.                 {
  349.                 case TE_LEFT:
  350.                     ob_ptr->ob_x = 0;
  351.                     break;
  352.                 case TE_RIGHT:
  353.                     ob_ptr->ob_x = par_ptr->ob_width - width;
  354.                     break;
  355.                 case TE_CNTR:
  356.                     ob_ptr->ob_x = (par_ptr->ob_width - width)>>1;
  357.                 }
  358.  
  359.                 if (par_ptr->ob_spec.tedinfo->te_font==SMALL)
  360.                     ob_ptr->ob_x += (int) ((long) (pos - text) * gr_sw);
  361.                 else
  362.                     ob_ptr->ob_x += (int) ((long) (pos - text) * gr_cw);
  363.                 break;
  364.             case G_BUTTON:
  365.                 width *= gr_cw;
  366.                 ob_ptr->ob_x = (par_ptr->ob_width - width)>>1;
  367.                 ob_ptr->ob_x += (int) ((long) (pos - text) * gr_cw);
  368.                 break;
  369.             case G_STRING:
  370.                 ob_ptr->ob_x = (int) ((long) (pos - text) * gr_cw);
  371.                 break;
  372.             default:
  373.                 return(FALSE);
  374.             }
  375.         }
  376.         else if ((unsigned char) par_ptr->ob_type==G_BOXCHAR)
  377.         {
  378.             if (par_ptr->ob_spec.obspec.character==hot)
  379.                 ob_ptr->ob_x = (par_ptr->ob_width - gr_cw)>>1;
  380.             else
  381.                 return(FALSE);
  382.         }
  383.         else if (hot) 
  384.             return(FALSE);
  385.  
  386.         if (hot=='\0')
  387.             ob_ptr->ob_flags |= HIDETREE;
  388.         else
  389.             ob_ptr->ob_flags &= ~HIDETREE;
  390.  
  391.         ob_ptr->ob_state &= 0x00ff;
  392.         ob_ptr->ob_state |= UpperChar(hot)<<8;
  393.  
  394.         return (TRUE);
  395.     }
  396.  
  397.     return(FALSE);
  398. }
  399.